package cn.com.nes.common;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class MyTest {

	public static Connection getJdbcForEnery() {
		Connection conn = null;
		//String url = "jdbc:mysql://cs.nes.com.cn:3308/energydb?characterEncoding=utf-8";
		
		String url = "jdbc:mysql://rm-2ze3340731300n995no.mysql.rds.aliyuncs.com:3306/nes_agent?characterEncoding=utf-8" ;
		
		String user = "ctcetest";
		String password = "NES@ctceZO1B3";
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		try {
			conn = DriverManager.getConnection(url, user, password);
			conn.setAutoCommit(false);
		} catch (SQLException e1) {
			e1.printStackTrace();
		}
		return conn;
	}
	
	public static int update(Connection conn, String sql, Object[] obj) {
		PreparedStatement ps = null;
		int cnt = 0;
		try {
			ps = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
			if (obj != null && obj.length > 0) {
				for (int i = 0; i < obj.length; i++) {
					ps.setObject(i + 1, obj[i]);
				}
			}
			cnt = ps.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
			// TODO: handle exception
		} finally {
			try {
				ps.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return cnt;
	}
	
	public static void  pushVideoAsRTSP(long id, String fileName) throws SQLException{
		Connection conn = getJdbcForEnery() ;
        try {
        	String sql =  "INSERT INTO `nes_agent`.`clue`(`uuid`, `cluestage`, `followupstatus`, `poolentrymode`, `cluesource`, `advertisementId`, `culestate`, `clueowner`, `cluename`, `cluecompany`, `companycontact`, `cluephone`, `numberhome`, `companyMemo`, `pooltype`, `personpost`, `businessdirection`, `companyfocus`, `projectname`, `personincharge`, `projectaddress`, `personphone`, `xzqhdm`, `longitude`, `latitude`, `sex`, `wechat`, `projectarea`, `picture1`, `picture2`, `picture3`, `memo`, `serial`, `openid`, `cluebelongtocompany`, `otherdata`, `createUid`, `createTime`, `modifyUid`, `modifyTime`, `isdelete`, `jsondata`, `templateId`) VALUES (?, '01', '01', '01', '07', '05087e30-66d0-490c-b6e2-b03828cf0b36', '01', NULL, NULL, NULL, ?, '13811766622', '北京 ', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '86', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, ?, 'oAe385I5VH4mtkLEyIYGtCO9AO74', '45', NULL, NULL, '2022-07-19 09:47:50', NULL, NULL, '0', NULL, NULL) " ;
        	for(int i=0;i<2000;i++) {
        		String uuid = String.valueOf(System.currentTimeMillis()+i) ;
        		String nickName = "吴玉兴"+ uuid;
        		String serial = String.valueOf(50000+i);
        		update(conn,sql ,new Object[] {uuid,nickName,serial}) ;
        		conn.commit();
        	}
        	System.out.println("OK");
        	
        }catch (Exception e){
            e.printStackTrace();
        }finally {
        	conn.close();
		}
    }
	
	public static void main(String[] args) throws SQLException {
		pushVideoAsRTSP(0,null) ;
	}
}
